import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Scanner;

public class T1 {
    public static void main(String[] args) {
        Connection connection = null;
        Statement statement = null;
        ResultSet resultSet =null;
        try {
            connection = DbUtil.getConnection();

            statement = connection.createStatement();

//            String sql = "insert  into user values(1,'admin','123456',500)";
//            int i = statement.executeUpdate(sql);
//            System.out.println("受影响行数:"+i);

            Scanner scanner = new Scanner(System.in);
            System.out.println("请输入用户名");
            String u = scanner.nextLine();
            System.out.println("请输入密码");
            String s = scanner.nextLine();

            // 准备sql语句
            String sql = "select * from user where name='"+u+"' and pwd='"+s+"'";
            resultSet =  statement.executeQuery(sql);
            // 处理结果
            if (resultSet.next()){
                System.out.println("登录成功！！");
            }else{
                System.out.println("登录失败，用户名或者密码错误！！");
            }

        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            DbUtil.close(resultSet,statement,connection);
        }


    }
}
